export default {
  onLoad() {
    // let pages = getCurrentPages();
    // let currPage = null;
    // if (pages.length) {
    //   currPage = pages[pages.length - 1];
    // }
    // console.log(currPage);

    this.__share__();
  },
  methods: {
    __openMap__(address) {
      // 打开地图
      wx.openLocation({
        latitude: address.location.lat,
        longitude: address.location.lng,
        scale: 16,
        name: address.name
      });
    },
    async __getMap__(address) {
      // 获取地图地址详情
      if (!address) {
        wx.showToast({
          title: '地址无效！',
          icon: 'none',
          mask: true
        });
        return;
      }
      wx.showLoading({ title: '加载中' });
      const url = 'https://apis.map.qq.com/ws/geocoder/v1/';
      const params = {
        key: 'XT4BZ-OM7CX-4IK4A-ZHZC4-U562E-4MFEY',
        output: 'json',
        address: address || ''
      };
      const res = await this.$http.get(url, params);
      wx.hideLoading();
      if (res.status != 0) {
        wx.showToast({
          title: res.message || '获取失败！',
          icon: 'none',
          mask: true
        });
        return;
      }
      this.__openMap__({ name: address, ...res.result });
    },
    __share__() {
      wx.showShareMenu({
        withShareTicket: true
      });
    }
  }
};
